package com.demo.student;

import com.demo.common.model.Student;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;

@Path("/students")
@Before(StudentInterceptor.class)
public class StudentController extends Controller {
	
	@Inject
	StudentService service;
	
	public void index() {
		setAttr("studentPage", service.paginate(getParaToInt(0, 1), 10));
		render("students.html");
	}

	public void add() {
	}

	@Before(StudentValidator.class)
	public void save() {
		service.save(getBean(Student.class));
		redirect("/students");
	}
	
	public void edit() {
		setAttr("student", service.findById(getParaToInt()));
	}

	@Before(StudentValidator.class)
	public void update() {
		service.update(getBean(Student.class));
		redirect("/students");
	}
	
	public void delete() {
		service.deleteById(getParaToInt());
		redirect("/students");
	}
}


